home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 4533 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.6 KB  |  55 lines

  1. Path: news.infi.net!usenet
  2. From: nngis@norfolk.infi.net (Greg DiGiorgio)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: How to copy from Array to Array ?
  5. Date: 5 Feb 1996 14:36:35 GMT
  6. Organization: Customer of InfiNet
  7. Message-ID: <4f54lj$b34@nw002.infi.net>
  8. References: <4f3ec3$3vp5@unix1.sncc.lsu.edu>
  9. Reply-To: nngis@norfolk.infi.net
  10. NNTP-Posting-Host: h-talisman.norfolk.infi.net
  11. Mime-Version: 1.0
  12. X-Newsreader: WinVN 0.99.3
  13.  
  14. In article <4f3ec3$3vp5@unix1.sncc.lsu.edu>, garaja@unix1.sncc.lsu.edu 
  15. says...
  16. >
  17. >Hello Everybody:
  18. >        I have a simple question on using Arrays and Pointers. Let's say
  19. >that i have two arrays declared as,
  20. >          double Array1[15000], and char Array2[15000].
  21. >    How do i sequentially copy elements from Array1 to Array2 using 
  22. "sprintf"
  23. >and "pointers" and how i can print the values in Array2. Any suggestions
  24. >will be appreciated.
  25. >
  26. >RAJABHUSHAN CHERUKURI (RAJ)
  27. >LOUISIANA STATE UNIVERSITY
  28. >garaja@unix1.sncc.lsu.edu
  29.  
  30. First, the size of Array1 might be 60K, but the size of Array2 is 15K,
  31. so you need a new Array2.
  32.  
  33. #include <string>
  34. #include <stdio.h>
  35. double array1[15000];
  36. char array2[15000][20];   /* assume 14 dig precision, decimal, leading
  37.                              zero, a NULL,a dn extra room just in case */
  38.  
  39. main() {
  40.         int i;
  41.         int res;
  42.     ... blah-blah ...  /* assume you init "array1" here */
  43.         for (i=0; i<10; i++) {
  44.                 res=sprintf(&(array2[i][0]),"%lf",array1[i]);
  45.                 if (res == EOF) printf("Error on #%d\n",i);
  46.                 else printf("Converted: %s",&(array2[i][0]));
  47.         }
  48. }
  49.  
  50. Hope this helps,
  51. Greg DiGiorgio
  52.  
  53. "The meek shall inherit the earth" - who says nice guys finish last?
  54.  
  55.